//
//  CCYTabBar.m
//  模拟-百思不得姐
//
//  Created by 程春玉 on 16/8/1.
//  Copyright © 2016年 chunyu. All rights reserved.
//

#import "CCYTabBar.h"

#import "jiaViewController.h"
@interface CCYTabBar()

@property (nonatomic, weak) UIButton *btn;


@end

@implementation CCYTabBar

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setBackgroundImage:[UIImage imageNamed:@"tabbar-light"]];
        UIButton *temp = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [temp setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon"] forState:(UIControlStateNormal)];
        
        [temp setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon"] forState:(UIControlStateHighlighted)];
        
        [temp addTarget:self action:@selector(jia) forControlEvents:UIControlEventTouchDown];
        
        temp.size = temp.currentBackgroundImage.size;
        [self addSubview:temp];
        self.btn = temp;
    }
    return self;
}


-(void)jia
{
      NSLog(@"加分享");
    jiaViewController *jiaView=[[jiaViewController alloc]init];
    
    [[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:jiaView animated:YES completion:nil];
    

    
}



- (void)layoutSubviews
{
    [super layoutSubviews];
    _btn.center = CGPointMake(self.width * 0.5, self.height * 0.5);
    NSInteger index = 0;
    for (UIView *btn in self.subviews) {
        if (![btn isKindOfClass:NSClassFromString(@"UITabBarButton")]) continue;
        btn.frame = CGRectMake((index > 1 ? index + 1 : index) * self.width / 5, 0, self.width / 5, self.height);
        index++;
    }
}


@end






